package doublePointers;

/**
 * @author huangxianjin
 * @date 2025/9/9 23:42
 * @description ""
 */
public class LC_125 {
    //自己的做法---StringBuilder的reverse方法
    public boolean isPalindrome(String s) {
        String lowerCase = s.toLowerCase();

        StringBuilder sb = new StringBuilder();
        for (char c : lowerCase.toCharArray()) {
            if (Character.isLetter(c) || Character.isDigit(c)) {
                sb.append(c);
            }
        }
        if (sb.toString().equals(sb.reverse().toString())) {
            return true;
        }
        return false;
    }

    //自己做法---双指针
    public boolean isPalindrome2(String s) {
        String lowerCase = s.toLowerCase();
        StringBuilder sb = new StringBuilder();
        for (char c : lowerCase.toCharArray()) {
            if (Character.isLetterOrDigit(c)) {
                sb.append(c);
            }
        }

        String str = sb.toString();
        int left = 0;
        int right = str.length() - 1;
        while (left < right) {
            if (str.charAt(left) != str.charAt(right)) {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}
